package hxy.bytecode.hauwei.a;

import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author eric
 * @program bytecode
 * @description
 * @date 2020/4/12
 */
public class Main {
    public static void main(String[] args) {

        ArrayList<Dic> arrayList = new ArrayList<>();

        // 全部变成MB
        Scanner scanner = new Scanner(System.in);
        String line = scanner.nextLine();

        for (int i = 0; i < Integer.parseInt(line); i++) {
            String s = scanner.nextLine();
            String c = s.substring(s.length() - 1);
            String numberStr = s.substring(0,s.length() - 1);
            Integer value = Integer.parseInt(numberStr);

            if ("G".equalsIgnoreCase(c)) {
                value = value * 1000;
            }
            if ("T".equalsIgnoreCase(c)) {
                value = value * 1000000;
            }

            Dic dic = new Dic();
            dic.setValue(value);
            dic.setInput(s);
            arrayList.add(dic);
        }

        for (int i = arrayList.size() - 1; i > 0; i--) {
            for (int j = 0; j < i; j++) {
                Dic dicj = arrayList.get(j);
                Integer valuej = dicj.getValue();
                Dic dicj1 = arrayList.get(j + 1);
                Integer valuej1 = dicj1.getValue();
                if (valuej > valuej1) {
                    arrayList.set(j, dicj1);
                    arrayList.set(j + 1, dicj);
                }
            }
        }

        for (Dic dic :arrayList){
            System.out.println(dic.getInput());
        }

    }
}

class Dic {
    Integer value;
    String input;

    public Integer getValue() {
        return value;
    }

    public void setValue(Integer value) {
        this.value = value;
    }

    public String getInput() {
        return input;
    }

    public void setInput(String input) {
        this.input = input;
    }
}